VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "TestProxy"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Private mProxy As Proxy

Public Sub testCreation1()
givenNamedProxy1
thenGlobalLoggerHasName1
End Sub
Public Sub testCreation2()
givenNamedProxy2
thenGlobalLoggerHasName2
End Sub

Public Sub testDestruction()
whenProxy3CreatedLocalToMethod
thenGlobalLoggerHasCreationAndDestruction
End Sub

Public Sub testDestructionWhenErrorRaised()
whenProxy4CreatedLocalToMethodWhereErrorRaised
thenGlobalLoggerHasCreationDestructionThenError
End Sub

Public Sub testForwardedErrorHandlerStillHasErrObject()
whenErrorRaised
thenCalledMethodRecordedErrObject
End Sub

'''
''
''
Private Sub givenNamedProxy1()
Set mProxy = New Proxy
mProxy.name = "proxy1"
End Sub
Private Sub givenNamedProxy2()
Set mProxy = New Proxy
mProxy.name = "proxy2"
End Sub

Private Sub whenProxy3CreatedLocalToMethod()
Dim aProxy As New Proxy
aProxy.name = "proxy3"
gLogger.Log "whenProxy3CreatedLocalToMethod"
End Sub
Private Sub whenProxy4CreatedLocalToMethodWhereErrorRaised()
On Error GoTo handler
proxy4CreatedNoErrorHandled
gLogger.Log "This Line Skipped"
handler:
gLogger.Log "error Handler"
End Sub
Private Sub whenErrorRaised()
Dim errObject As Object
Set errObject = Err
On Error GoTo handler
Err.Raise 1001
Exit Sub
handler:
recordError
End Sub
Private Sub recordError()
gLogger.Log Err.Description
gLogger.Log Err.number
End Sub
Private Sub proxy4CreatedNoErrorHandled()
''Create and name Proxy
Dim aProxy As New Proxy
aProxy.name = "proxy4"
''Perform some processing
gLogger.Log "proxy4CreatedNoErrorHandling"
''Raise some error
Err.Raise 1001
''Some processing skipped
gLogger.Log "This Line Skipped"
End Sub

Private Sub thenGlobalLoggerHasName1()
assert.equals gLogger.Count, 1, "logger has one message"
assert.equals gLogger.First, "proxy1 created", "proxy1 created"
End Sub
Private Sub thenGlobalLoggerHasName2()
assert.equals gLogger.Count, 1, "logger has one message"
assert.equals gLogger.First, "proxy2 created", "proxy2 created"
End Sub
Private Sub thenGlobalLoggerHasCreationAndDestruction()
assert.equals gLogger.Count, 3, "logger has three messages"
assert.equals gLogger.First, "proxy3 created", "proxy3 created"
assert.equals gLogger.Second, "whenProxy3CreatedLocalToMethod", "method runs"
assert.equals gLogger.Third, "proxy3 destroyed", "proxy3 destroyed"
End Sub
Private Sub thenGlobalLoggerHasCreationDestructionThenError()
assert.equals gLogger.Count, 4, "logger has four messages"
assert.equals gLogger.First, "proxy4 created", "proxy4 created"
assert.equals gLogger.Second, "proxy4CreatedNoErrorHandling", "proxy4 maintained"
assert.equals gLogger.Third, "proxy4 destroyed", "proxy4 destroyed"
assert.equals gLogger.Fourth, "error Handler", "error Handler"
End Sub
Private Sub thenCalledMethodRecordedErrObject()
assert.equals gLogger.Count, 2, "Error recored has two messages"
assert.equals gLogger.First, "Application-defined or object-defined error", "thenCalledMethodRecordedErrObject"
assert.equals gLogger.Second, 1001, "Error number"
End Sub

'OPTIONAL METHODS
Public Sub setup()
Set gLogger = New Logger
End Sub
Public Sub teardown()
'NB mProxy has to be destroyed now in order for the log of its destruction to
'take place now so that is does not occur just before the next setup()
Set mProxy = Nothing
End Sub

Public Function NumOfAsserts() As Long
NumOfAsserts = 16
End Function

